<style>.coupon_class{width:300px;}
    label{
        margin-bottom:0px !important;

    }

</style>
<div class="form">
    <?php
    $form = $this->beginWidget('GxActiveForm', array(
        'id' => 'coupons-form',
        'enableAjaxValidation' => false,
            ));
    ?>

    <p class="note">
        <?php echo Yii::t('app', 'Fields with'); ?> <span class="required">*</span> <?php echo Yii::t('app', 'are required'); ?>.
    </p>

    <?php echo $form->errorSummary($model); ?>

    <div class="row">
        <div class="rowLabel coupon_class"><?php echo $form->labelEx($model, 'name'); ?>
        </div>
        <div class="rowControl"><?php echo $form->textField($model, 'name', array('maxlength' => 200)); ?>
            <?php echo $form->error($model, 'name'); ?>
        </div><!-- row -->
    </div>


    <div class="row">
        <div class="rowLabel coupon_class"><?php echo $form->labelEx($model, 'description'); ?>
        </div>
        <div class="rowControl"><?php echo $form->textArea($model, 'description'); ?>
            <?php echo $form->error($model, 'description'); ?>
        </div><!-- row -->
    </div>


    <div class="row">
        <div class="rowLabel coupon_class"><?php echo $form->labelEx($model, 'inprice'); ?>
        </div>
        <div class="rowControl"><?php echo $form->textField($model, 'inprice'); ?>
            <?php echo $form->error($model, 'inprice'); ?>
        </div><!-- row -->
    </div>

    <div class="row">
        <div class="rowLabel coupon_class"><?php echo $form->labelEx($model, 'inpercentage'); ?>
        </div>
        <div class="rowControl"><?php echo $form->textField($model, 'inpercentage'); ?>
            <?php echo $form->error($model, 'inpercentage'); ?>
        </div><!-- row -->
    </div>
    <h3><?php $model->apply_discount_to = 1; //echo $form->labelEx($model,'apply_discount_to');   ?>Apply Discount To:</h3>
    <div class="row">
        <div class="rowControl">
            <div style="margin-left:300px;">
                <?php
                if (isset($_POST['Coupons']['apply_discount_to']))
                    $model->apply_discount_to = $_POST['Coupons']['apply_discount_to'];
                ?>


                <?php echo $form->radioButtonList($model, 'apply_discount_to', couponArray(), array('onclick' => 'return CheckCheapest(this.id);')); ?>
            </div>
            <br />
            <?php echo $form->error($model, 'apply_discount_to'); ?>
        </div><!-- row -->
    </div>
    <br />
    <div class="row">
        <div class="rowLabel coupon_class"><?php echo $form->labelEx($model, 'require_all_products_to_match'); ?>
        </div>
        <div class="rowControl">
            <?php echo $form->checkBox($model, 'require_all_products_to_match'); ?>
            <?php echo $form->error($model, 'require_all_products_to_match'); ?>
        </div><!-- row -->
    </div>

    <br />
    <div class="row">
        <div class="rowLabel coupon_class"><?php echo $form->labelEx($model, 'order_limit'); ?>
        </div>
        <div class="rowControl">
            <?php echo $form->checkBox($model, 'order_limit', array('onclick' => 'return DisplayOrder(this.id);')); ?>
            <?php echo $form->error($model, 'order_limit'); ?>
        </div><!-- row -->
    </div>
    <br />
    <div id="min_max_order" style="display:<?php if ($model->order_limit == 1) { ?>''<?php } else { ?>none<?php } ?>;">
        <div class="row">
            <div class="rowLabel coupon_class"><?php echo $form->labelEx($model, 'minimum_order'); ?>
            </div>
            <div class="rowControl"><?php echo $form->textField($model, 'minimum_order'); ?>
                <?php echo $form->error($model, 'minimum_order'); ?>
            </div><!-- row -->
        </div>

        <div class="row">
            <div class="rowLabel coupon_class"><?php echo $form->labelEx($model, 'maximum_order'); ?>
            </div>
            <div class="rowControl"><?php echo $form->textField($model, 'maximum_order'); ?>
                <?php echo $form->error($model, 'maximum_order'); ?>
            </div><!-- row -->
        </div>

    </div>


    <div class="row">
        <div class="rowLabel coupon_class"><?php echo $form->labelEx($model, 'restrict_by_date'); ?>
        </div>
        <div class="rowControl">
            <?php echo $form->checkBox($model, 'restrict_by_date', array('onclick' => 'return DisplayHideDate(this.id);')); ?>
            <?php echo $form->error($model, 'restrict_by_date'); ?>
        </div><!-- row -->
    </div>
    <br />
    <div id="restrict_date_id" style="display:none;">

        <div class="row">
            <div class="rowLabel coupon_class"><?php echo $form->labelEx($model, 'valid_from_date'); ?>
            </div>
            <div class="rowControl"><?php
            $form->widget('zii.widgets.jui.CJuiDatePicker', array(
                'model' => $model,
                'attribute' => 'valid_from_date',
                'value' => $model->valid_from_date,
                'options' => array(
                    'changeYear' => true,
                    'dateFormat' => 'yy-mm-dd',
                ),
            ));
            ;
            ?>
                <?php echo $form->error($model, 'valid_from_date'); ?>
            </div><!-- row -->
        </div>

        <div class="row">
            <div class="rowLabel coupon_class"><?php echo $form->labelEx($model, 'valid_to_date'); ?>
            </div>
            <div class="rowControl"><?php
                $form->widget('zii.widgets.jui.CJuiDatePicker', array(
                    'model' => $model,
                    'attribute' => 'valid_to_date',
                    'value' => $model->valid_to_date,
                    'options' => array(
                        'changeYear' => true,
                        'dateFormat' => 'yy-mm-dd',
                    ),
                ));
                ;
                ?>
                <?php echo $form->error($model, 'valid_to_date'); ?>
            </div><!-- row -->
        </div>
    </div>

    <div class="row">
        <div class="rowLabel coupon_class"><?php echo $form->labelEx($model, 'maximum_number_of_redemptions_per_code'); ?>
        </div>
        <div class="rowControl"><?php echo $form->textField($model, 'maximum_number_of_redemptions_per_code'); ?>
            <?php echo $form->error($model, 'maximum_number_of_redemptions_per_code'); ?>
        </div><!-- row -->
    </div>

    <div class="row">
        <div class="rowLabel coupon_class"><?php echo $form->labelEx($model, 'maximum_number_of_redemptions_per_user'); ?>
        </div>
        <div class="rowControl"><?php
            if ($model->maximum_number_of_redemptions_per_user == 0)
                $model->maximum_number_of_redemptions_per_user = 1;

            echo $form->textField($model, 'maximum_number_of_redemptions_per_user');
            ?>
            <?php echo $form->error($model, 'maximum_number_of_redemptions_per_user'); ?>
        </div><!-- row -->
    </div>

    <div class="row" id="max_no_of_prodcts_dis" style="display:none;">
        <div class="rowLabel coupon_class"><?php echo $form->labelEx($model, 'maximum_number_of_prodcuts_to_discount'); ?>
        </div>
        <div class="rowControl"><?php echo $form->textField($model, 'maximum_number_of_prodcuts_to_discount'); ?>
            <?php echo $form->error($model, 'maximum_number_of_prodcuts_to_discount'); ?>
        </div><!-- row -->
    </div>
    <div id="class_course_restrict_id" style="display:<?php if ($model->apply_discount_to == 2 || $model->apply_discount_to == 3 || $model->apply_discount_to == 4 || $model->apply_discount_to == 5) { ?>''<?php } else { ?>none<?php } ?>;">

        <div class="row">
            <br />
            <div class="rowLabel coupon_class">All Classes</div>
            <div class="rowControl">
                <?php
                $this->widget('common.extensions.multicomplete.MultiComplete', array(
                    'model' => $ClassCourseCategoryUsersRestrictionCoupon,
                    'splitter' => ',',
                    'name' => 'ClassCourseCategoryUsersRestrictionCoupon[classes_id]',
                    'sourceUrl' => $this->createUrl('coupons/autocompleteClass'),
                    'options' => array(
                        'showAnim' => 'fold',
                    ),
                ));
                ?>
                <?php echo $form->error($ClassCourseCategoryUsersRestrictionCoupon, 'classes_id'); ?>
            </div><!-- row -->
        </div>
        <br />

        <div class="row">
            <br />
            <div class="rowLabel coupon_class">All Courses</div>
            <div class="rowControl">
                <?php
                $this->widget('common.extensions.multicomplete.MultiComplete', array(
                    'model' => $ClassCourseCategoryUsersRestrictionCoupon,
                    'splitter' => ',',
                    'name' => 'ClassCourseCategoryUsersRestrictionCoupon[courses_id]',
                    'sourceUrl' => $this->createUrl('coupons/autocompleteCourse'),
                    'options' => array(
                        'showAnim' => 'fold',
                    ),
                ));
                ?>

                <?php echo $form->error($ClassCourseCategoryUsersRestrictionCoupon, 'courses_id'); ?>
                <div class="errorMessage" id="class_course_error" style="display:none;">Class/Course can not be blank.</div>
            </div><!-- row -->
        </div>
        <br />
    </div>

    <div class="row">
        <div class="rowLabel coupon_class"><?php echo $form->labelEx($model, 'status'); ?></div>
        <div class="rowControl"><?php echo $form->dropDownList($model, 'status', array("1" => "Active", "0" => "Inactive")); ?>    
            <?php echo $form->error($model, 'status'); ?>
        </div><!-- row -->
    </div>



    <div class="row">        
          <div class="rowLabel coupon_class">&nbsp;</div>
          <div class="rowControl">
        <?php
        echo GxHtml::submitButton(Yii::t('app', 'Save'), array('onclick' => 'return validationClassCourse();','class'=>'btn btn-primary'));
        $this->endWidget();
        ?></div>
    </div>
</div>
<!-- form -->
<?php if ($model->apply_discount_to == 2 || $model->apply_discount_to == 3 || $model->apply_discount_to == 4 || $model->apply_discount_to == 5) { ?>
    <script language="javascript">
        $('#max_no_of_prodcts_dis').show();
    </script>
<?php } ?>

<script language="javascript">
    $(document).ready(function() {
        if($('#Coupons_restrict_by_date').is(':checked')) { $('#restrict_date_id').show();}
    });


    function validationClassCourse(){
        var myclasscourse = '';
        if($('#Coupons_apply_discount_to_1').is(':checked') || $('#Coupons_apply_discount_to_2').is(':checked') || $('#Coupons_apply_discount_to_3').is(':checked') || $('#Coupons_apply_discount_to_4').is(':checked')) { 
            if($("#ClassCourseCategoryUsersRestrictionCoupon_classes_id").val()=="" && $("#ClassCourseCategoryUsersRestrictionCoupon_courses_id").val()==""){
                myclasscourse=1;
            }
        }
        if(myclasscourse==1){
            $('#class_course_error').show();
            return false;
        }
    }


    function DisplayOrder(id){
        if($('#'+id).is(':checked')) { $('#min_max_order').show();
        } else { 
            $('#min_max_order').hide();
        }
    }



    function DisplayHideDate(id){
        if($('#'+id).is(':checked')) { $('#restrict_date_id').show(); 
        } else { 
            $('#restrict_date_id').hide(); 
            $('#Coupons_valid_from_date').val(''); 
            $('#Coupons_valid_to_date').val(''); 
        }
    }


    function CheckCheapest(id){
	
        if((id=="Coupons_apply_discount_to_1" || id=="Coupons_apply_discount_to_2"  || id=="Coupons_apply_discount_to_3"  || id=="Coupons_apply_discount_to_4") && $('#'+id).is(':checked')==true){
            $('#class_course_restrict_id').show();
        }else{
            $('#class_course_restrict_id').hide();
        }
	
        if((id=="Coupons_apply_discount_to_3" || id=="Coupons_apply_discount_to_4") && $('#'+id).is(':checked')==true){
            $('#max_no_of_prodcts_dis').show();
        }else if(id !="Coupons_apply_discount_to_3" && id !="Coupons_apply_discount_to_4"){
            $('#max_no_of_prodcts_dis').hide();
        }
    }


</script>